<?php
/**
 * 管理员模型
 * ============================================================================
 * 版权所有 2017 福建华晟网络科技，并保留所有权利。
 * 网站地址: http://www.fldcms.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: fld
 * Date: 2017-07-01
 */
namespace app\common\model;
class AdminModel extends BaseModel {
	private $table_name = 'admin';
	
	/**
	 * 获取管理员列表
	 * @param unknown $result
	 */
	public function getAdminList($result){
		$order = "admin_id desc";
		$list = $this->select_table_by_page($this->table_name,$result['condition'],'*',$order,$result['query']);
		return $list;
	}
	/**
	 * 添加管理员
	 */
	public function addData(){
		$data = array();
		$data['admin_name'] = input('post.admin_name');
		$data['admin_truename'] = input('post.admin_truename');
		$data['admin_password'] = encrypt(input('post.password'));
		$data['admin_role_id'] = input('post.admin_role_id');
		$res = $this->add_table($this->table_name,$data);
		if($res !== false){
			model('ActionLog')->action_log("添加","添加管理员成功，管理员编号=".$res."，管理员账号=".input('post.admin_name'));
			return $res;
		}else{
			return false;
		}
	}
    /**
     * 获取单个管理员信息
     * @param unknown $condition
     */
	public function getAdminInfo($condition){
		return $this->find_table($this->table_name,$condition);
	}
	/**
	 * 更新管理员信息
	 */
	public function updateData(){
		$admin_id = input('post.admin_id');
		$data['admin_truename'] = input('post.admin_truename');
		$res = $this->update_table($this->table_name,array('admin_id'=>$admin_id),$data,1);
		if($res !== false){
			model('ActionLog')->action_log("编辑","编辑管理员成功，管理员编号=".$admin_id);
			return $res;
		}else{
			return false;
		}
	}
	/**
	 * 删除管理员信息
	 */
	public function deleteData(){
		$admin_id = input('param.admin_id');
		$admin_info = $this->getAdminInfo(array('admin_id'=>$admin_id));
		$res = $this->delete_table($this->table_name,array('admin_id'=>$admin_id));
		if($res !== false){
			model('ActionLog')->action_log("删除","删除管理员成功，管理员编号=".$admin_info['admin_id']."，管理员账号=".$admin_info['admin_name']);
			return $res;
		}else{
			return false;
		}
	}
	/**
	 * 更新密码
	 */
	public function resetPwd(){
		$admin_id = input('post.admin_id');
		$pwd = input('post.pwd');
		$data['admin_password'] = encrypt($pwd);
		$res = $this->update_table($this->table_name,array('admin_id'=>$admin_id),$data,1);
		if($res !== false){
			model('ActionLog')->action_log("编辑","编辑管理员密码成功，管理员编号=".$admin_id);
			return $res;
		}else{
			return false;
		}
	}
}
